#!/bin/sh

NAME="Telegram Bot daemon"

. /usr/share/common

start() {
	echo "Starting $NAME"

	start_daemon
}

stop() {
	echo_title "Stopping $NAME"

	stop_daemon
}

status() {
	if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE" 2>/dev/null) 2>/dev/null; then
		echo "$NAME is running (pid $(cat "$PIDFILE"))"
		return 0
	fi
	if pidof "$NAME" >/dev/null 2>&1; then
		echo "$NAME is running (pid $(pidof $NAME))"
		return 0
	fi
	echo "$NAME is not running"
	return 3
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	status)
		status
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
		;;
esac

exit 0
